package com.hopu.blb_erp.controller;

import com.hopu.blb_erp.entity.TPar;
import com.hopu.blb_erp.entity.TRelation;
import com.hopu.blb_erp.entity.User;
import com.hopu.blb_erp.service.TRelationService;
import com.hopu.blb_erp.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

@Api
@RestController
public class TRelationController {
    @Autowired
    private TRelationService tRelationService;
    @Autowired
    private UserService userService;

    @ApiOperation("添加客户供应商关系表")
    @PostMapping("/tRelation")
    public ResponseEntity<String> addTRelation(@RequestBody TRelation tRelation){
        tRelationService.save(tRelation);
        return ResponseEntity.ok("ok");
    }


    @ApiOperation("更新客户供应商关系表(同意申请)")
    @PutMapping("/customer/supplier/{ok}")
    public ResponseEntity<String> modifyTRelation(@PathVariable("ok") String ok,@RequestBody TPar tPar){
        tPar.setTParStatus(ok);
        tPar.setTParStatus2(ok);
        if ("0".equals(tPar.getTParRel())){
            tRelationService.addSupplier(tPar);
        }
        if ("1".equals(tPar.getTParRel())){
            tRelationService.addCustomer(tPar);
        }
        return ResponseEntity.ok("ok");
    }




}
